﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.Common
{
    public class EmailHelper
    {
        public static bool SendLineBarCodeMail(string[] Emailers,string strMsg ,string Subject, bool IsBodyHtml)
        {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            foreach(string s in Emailers)
            {
                string mailAddress = s + "@lamex.com.hk";
                msg.To.Add(mailAddress);
            }

            msg.Bcc.Add("Robin Yang@lamex.com.hk");
            //msg.To.Add("zhongjie.yang@lamex.com.hk");
            //msg.CC.Add("Bill.Luo@lamex.com.hk");
            //msg.CC.Add("Bill.Luo@lamex.com.hk");
            msg.From = new MailAddress("mailsender@lamex.com.hk", "admin", System.Text.Encoding.UTF8);
            /* 上面3个参数分别是发件人地址（可以随便写），发件人姓名，编码*/
            msg.Subject = Subject;//邮件标题    
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码    
            // msg.Body = "Dear ALL  良率报表详见附件，请查收！";//邮件内容    
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码    
            msg.IsBodyHtml = IsBodyHtml;//是否是HTML邮件    
            msg.Priority = MailPriority.Normal;//邮件优先级    
            msg.Body = strMsg;
            
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("mailsender@moptron.biz", "Bl@7701167//");
            //上述写你的GMail邮箱和密码    
            client.Port = 25;//Gmail使用的端口  25  
            client.Host = "172.23.134.118";
            // client.EnableSsl = true;//经过ssl加密    
            object userState = msg;
            try
            {
                client.Send(msg);
                GC.Collect();
                return true;

            }
            catch
            {
                return false;
            }
        }
    }
}
